package com.team.party.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.team.party.bean.Activity;
import com.team.party.bean.Manager;
import com.team.party.bean.Sjst;
import com.team.party.bean.Society;
import com.team.party.bean.Student;
import com.team.party.mapper.ManagerMapper;
import com.team.party.service.ManagerService;
@Service
public class ManagerServiceImpl implements ManagerService {
	@Autowired
	private ManagerMapper managermapper;
	
	@Override
	public Manager serchManager(String username) throws Exception {
		// TODO Auto-generated method stub
		Manager manager = new Manager();
		manager.setMan_username(username);
		return managermapper.serchManager(manager);
	}

	@Override
	public void logout() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Society serchMySociety(String soc_no) throws Exception {
		// TODO Auto-generated method stub
		Manager manager =  new Manager();
		manager.setSoc_no(soc_no);
		Society Gmanager = managermapper.serchMySociety(manager);
		return Gmanager;
	}

	@Override
	public Boolean changeSocietyMessage(String soc_unit, String soc_locat, String soc_man, String soc_tele,
			int soc_count, String soc_intro, String soc_no) throws Exception {
		// TODO Auto-generated method stub
		Society society = new Society();
		society.setSoc_unit(soc_unit);
		society.setSoc_locat(soc_locat);
		society.setSoc_man(soc_man);
		society.setSoc_tele(soc_tele);
		society.setSoc_count(soc_count);
		society.setSoc_intro(soc_intro);
		society.setSoc_no(soc_no);

		return managermapper.changeSocietyMessage(society);
	}

	@Override
	public List<Student> serchSocietyNumber(String soc_no) throws Exception {
		// TODO Auto-generated method stub
		Manager manager = new Manager();
		manager.setSoc_no(soc_no);
		List<Student> Gstu = managermapper.serchSocietyNumber(manager);
		return Gstu;
	}

	@Override
	public Boolean insertSocietyNumber(String stu_no, String soc_no) throws Exception {
		// TODO Auto-generated method stub
		Sjst sjst = new Sjst();
		sjst.setStu_no(stu_no);
		sjst.setSoc_no(soc_no);
		
		sjst.setSjst_start(new Date());

		return managermapper.insertSocietyNumber(sjst);
	}

	@Override
	public Boolean changeNumberMessage(String stu_name, String stu_sex, int stu_age, String stu_tel, String stu_form,
			String stu_scho, String stu_no) throws Exception {
		// TODO Auto-generated method stub
//		System.out.println("services==============="+stu_scho);
		Student student = new Student();
		student.setStu_name(stu_name);
		student.setStu_sex(stu_sex);
		student.setStu_age(stu_age);
		student.setStu_tel(stu_tel);
		student.setStu_form(stu_form);
		student.setStu_no(stu_no);
		student.setStu_scho(stu_scho);
		
		return managermapper.changeNumberMessage(student);
	}

	@Override
	public Boolean deleteSocietyNumber(String stu_no, String soc_no) throws Exception {
		// TODO Auto-generated method stub
		Sjst sjst = new Sjst();
		sjst.setStu_no(stu_no);
		sjst.setSoc_no(soc_no);
		
		return managermapper.deleteSocietyNumber(sjst);
	}

	@Override
	public List<Activity> serchMyActivity(String soc_no) {
		// TODO Auto-generated method stub
		Manager manager = new Manager();
		manager.setSoc_no(soc_no);
		
		List<Activity> activityList = new ArrayList<Activity>();

		try {
			activityList = managermapper.serchMyActivity(manager);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return activityList;
	}
	
	@Override
	public Activity serchActivityByNo(String act_no) throws Exception{
		Activity activity = new Activity();
		activity.setAct_no(act_no);
		activity = managermapper.serchActivityByNo(activity);
		
		return activity;
	}

	@Override
	public Boolean saveActivity(String act_no, String soc_no, String act_name, String act_loc, Date act_start,
			Date act_end, int act_public, String act_intro, String act_pic) throws Exception {
		// TODO Auto-generated method stub
		Activity activity = new Activity();
		
		activity.setAct_no(act_no);
		activity.setSoc_no(soc_no);
		activity.setAct_name(act_name);
		activity.setAct_loc(act_loc);
		activity.setAct_start(act_start);
		activity.setAct_end(act_end);
		activity.setAct_public(act_public);
		activity.setAct_intro(act_intro);
		activity.setAct_pic(act_pic);
		
		return managermapper.insertActivity(activity);
	}

	@Override
	public Boolean changeActivityMessage(String act_name, String act_loc, Date act_start, Date act_end,
			String act_intro, String act_pic, String act_no,int act_public) throws Exception {
		// TODO Auto-generated method stub
		
		Activity activity = new Activity();
		activity.setAct_name(act_name);
		activity.setAct_loc(act_loc);
		activity.setAct_start(act_start);
		activity.setAct_end(act_end);
		activity.setAct_intro(act_intro);
		activity.setAct_pic(act_pic);
		activity.setAct_no(act_no);
		activity.setAct_public(act_public);
		return managermapper.changeActivityMessage(activity);
	}

	@Override
	public Boolean deleteActivity(String act_no) throws Exception {
		// TODO Auto-generated method stub
		Activity activity = new Activity();
		activity.setAct_no(act_no);
		
		return managermapper.deleteActivity(activity);
	}

	@Override
	public List<Student> serchSocietyNumberByFuzzy(String soc_no, String stu_no, String stu_name) throws Exception {
		// TODO Auto-generated method stub
		
		return managermapper.serchSocietyNumberByFuzzy(soc_no, stu_no, stu_name);
	}

	
	@Override
	public List<Activity> serchMyActivityByFuzzy(String soc_no, String act_no, String act_name) throws Exception {
		// TODO Auto-generated method stub
		return managermapper.serchMyActivityByFuzzy(soc_no, act_no, act_name);
	}

	@Override
	public int getSocietyNum(String soc_no) throws Exception {
		// TODO Auto-generated method stub
		return managermapper.getSocietyNum(soc_no);
	}
	
}
